package com.baitap.Module;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.security.PublicKey;

import javax.swing.border.*;
import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextField;
import javax.swing.SwingConstants;

public class ptGUI extends JFrame {
	JTextField txta, txtb;
	JTextField txtkq;
	public ptGUI(){}
	private JPanel contentPane;
	private JPanel DisplayPanel = new JPanel();
	private JPanel buttonPanel = new JPanel();
	private JTextField displayField = new JTextField();
	private JButton[] button = new JButton[6];
	private String[] buttonName = {"Cộng", "Trừ", "Nhân", "Chia",
									"Xóa", "Thoát"}; 
	//Khoi tao GUI
	public void intGUI(EvtProcessor evtProcessor){
		
		//Lấy nội dung  để thiết lập Panel
		JPanel pnBorder=new JPanel();
		pnBorder.setLayout(new BorderLayout());
		JPanel pnNorth=new JPanel();
		JLabel lblTitle=new JLabel("Cộng Trừ Nhân Chia");
		pnNorth.add(lblTitle);
		pnBorder.add(pnNorth,BorderLayout.NORTH);
		lblTitle.setForeground(Color.BLUE);
		Font ft=new Font("arial", Font.BOLD, 25);
		lblTitle.setFont(ft);
		
				Border  southborder
		=BorderFactory.createLineBorder(Color.RED);
		TitledBorder southTitleBorder=
				new TitledBorder(southborder, "Chọn tác vụ");
		pnNorth.setBorder(southTitleBorder);
		
		JPanel pnSouth=new JPanel();
		pnSouth.setPreferredSize(new Dimension(0, 30));
		pnSouth.setBackground(Color.PINK);
		JPanel pns1=new JPanel();
		pns1.setBackground(Color.BLUE);
		pnSouth.add(pns1);
		JPanel pns2=new JPanel();
		pns2.setBackground(Color.RED);
		pnSouth.add(pns2);
		JPanel pns3=new JPanel();
		pns3.setBackground(Color.YELLOW);
		pnSouth.add(pns3);
		pnBorder.add(pnSouth,BorderLayout.SOUTH);
		
		JPanel pnCenter=new JPanel();
		pnCenter.setLayout(new BoxLayout(pnCenter, BoxLayout.Y_AXIS));
		pnBorder.add(pnCenter,BorderLayout.CENTER);
		
		Border  centerborder
		=BorderFactory.createLineBorder(Color.RED);
		TitledBorder centerTitleBorder=
				new TitledBorder(centerborder, "nhập 2 số a và b:");
		pnCenter.setBorder(centerTitleBorder);

		JPanel pna=new JPanel();
		JLabel lbla=new JLabel("nhập a:");
		txta=new  JTextField(15);
		pna.add(lbla);
		pna.add(txta);
		pnCenter.add(pna);
		
		JPanel pnb=new JPanel();
		JLabel lblb=new JLabel("nhập b:");
		txtb=new  JTextField(15);
		pnb.add(lblb);
		pnb.add(txtb);
		pnCenter.add(pnb);
		
		JPanel pnkq=new JPanel();
		JLabel lblkq=new JLabel("Kết quả:");
		txtkq=new  JTextField(15);
		pnkq.add(lblkq);
		pnkq.add(txtkq);
		pnCenter.add(pnkq);
		
		lbla.setPreferredSize(lblkq.getPreferredSize());
		lblb.setPreferredSize(lblkq.getPreferredSize());
		
		JPanel pnc=new JPanel();
		JPanel pnpheptoan=new JPanel();
		pnpheptoan.setLayout(new GridLayout(2, 4));
		pnpheptoan.setBorder(new TitledBorder(BorderFactory.createLineBorder(Color.BLACK),"Chọn Xử Lý"));
		
		for (int i = 0; i < 6; i++) {
						
			button[i]=new JButton(buttonName[i]);
			pnpheptoan.add(button[i]);
			button[i].addActionListener(evtProcessor);
		}
		
		
		pnc.add(pnpheptoan);
		pnCenter.add(pnc);
		
		
		//Sắp xếp ContentPane
	
		//Khoi tao tinh toan
		evtProcessor.intPhepTinh();
		Container con=getContentPane();
		con.add(pnBorder);
	}
	
	
	
	// khoi tao gia tri cua Disp;ayFild
	public void setDisplayField(String val){
		displayField.setText(val);		
	}
	
	public String getDisplayFieldText(){
		return displayField.getText();
	}

	


}
